<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
%>
<html>
<head>
    <meta charset="utf-8">
    <title>任务管理</title>
    <link href="<%=path %>/web/userinfo/css/my_info.css" rel="stylesheet">
    <link rel="stylesheet" href="<%=path%>/web/userinfo/css/log.css">
    <link rel="stylesheet" href="<%=path%>/web/userinfo/css/page.css">
</head>
<body>
<div class="my_info_title">任务管理</div>
<div class="my_info_title_3" style="margin-bottom: 20px">
    <ul>
        <li data-title="发布的任务"  style="margin-left:140px;border-left: 1px solid #CCC;">发布的任务</li>
        <li data-title="接受的任务"  class="task_head">接受的任务</li>
        <li data-title="完成的任务"  >完成的任务</li>
    </ul>
</div>
<div class="manage-jobs">
    <div class="single-manage-jobs table-responsive">

    </div>
</div>

<script src="<%=path %>/web/static/js/modules/jquery-3.4.1.min.js"></script>
<script src="<%=path %>/web/static/layui/layui.all.js"></script>
</body>
</html>
<script>
    $(function () {
        initData(1);


        $(".single-manage-jobs").on("click", ".meneame a", function () { //给页码加点击事件
            var pageNum = $(this).data("id");
            initData(pageNum);
            return false;
        })

        $(".my_info_title_3 li").click(function(){
            if($(this).data("title")=="发布的任务")
            {
                $(window.parent.document).find("#crowdfunding_iframe").attr("src","<%=path%>/web/userinfo/task");
            }
            if($(this).data("title")=="接受的任务")
            {
                $(window.parent.document).find("#crowdfunding_iframe").attr("src","<%=path%>/web/userinfo/acceptTask");
            }
            if($(this).data("title")=="完成的任务")
            {
                $(window.parent.document).find("#crowdfunding_iframe").attr("src","<%=path%>/web/userinfo/finishTask");
            }
        })

        $(".single-manage-jobs").on("click", "a.giveUp", function () {             //放弃任务
            var taskId = $(this).data("id");
            layer.confirm("确认放弃任务吗", { title: "放弃确认",btn: ['确认', '取消'] }, function (index) {
                layer.close(index);
                $.get("${pageContext.request.contextPath}/web/userinfo/giveUpByTaskId",{taskId:taskId},function () {
                    initData(1);
                    layer.msg('成功放弃', {icon: 5});
                })
            });
        });

        $(".single-manage-jobs").on("click", "a.finish", function () {             //完成任务
            var taskId = $(this).data("id");
            layer.prompt({
                formType: 2,
                title: '请输入完成依据'
            }, function(value, index, elem){
                var finishReason = value;
                layer.close(index);
                layer.confirm("确认提交完成申请", { title: "完成申请",btn: ['确认', '取消'] }, function (index) {
                    layer.close(index);
                    $.get("${pageContext.request.contextPath}/web/userinfo/finishByTaskId",{taskId:taskId,finishReason:finishReason},function () {
                        init(1);
                        layer.msg('等待审核', {icon: 5});
                    })
                });
            })

        });

    })


    function initData(pageNum) {   //发布任务页面初始化
        var pageNum = {pageNum: pageNum};
        $.get("${pageContext.request.contextPath}/web/userinfo/acceptTaskList", pageNum, function (mes) {
                $(".single-manage-jobs").empty();
                $(".single-manage-jobs").html(mes);
            }
        );
    }
</script>